package cn.china.springboot.controller;

import cn.china.springboot.serviceimpl.ProductServiceImpl;

import entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
@CrossOrigin
@RestController
public class ProductController {
    @Autowired
    ProductServiceImpl psi;

    /**
     * 查询菜品类型
     * @param response
     * @return
     */
    @RequestMapping(value = "/selectByProductType" ,produces = "application/json;charset:UTF-8")
    public List<String> selectByProductType(HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        return psi.selectByProductType();
    }

    /**
     * 查询菜品
     * @param type
     * @param response
     * @return
     */
    @RequestMapping(value = "/selectByType" ,produces = "application/json;charset:UTF-8")
    public List<Product> selectByType(@RequestParam String type, @RequestParam Integer currentPage, HttpServletResponse response){
        response.setHeader("Access-Control-Allow-Origin", "*");
        return psi.selectByType(type,currentPage);
    }

    /**
     * 分页页数
     * @param type
     * @param response
     * @return
     */
    @RequestMapping(value = "/getCountByType" ,produces = "application/json;charset:UTF-8")
    public int getCountByType(@RequestParam String type, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        return psi.getCountByType(type);
    }
}
